layui.use(['form', 'table', 'layer', 'laydate'], function (form, table, layer, laydate) {
    //提交按钮监听
    form.on("submit(updateSubmit)", function (data) {
        const userInfo = data.field;
        console.log("用户信息:", JSON.stringify(userInfo));
        $.ajax({
            type: "post",
            url: "../user/add",
            data: JSON.stringify(userInfo),
            headers: {
                'Content-Type': 'application/json;charset=utf-8'
            },
            success: function (data) {
                if (parseInt(data.obj) > 0) {
                    layer.msg(
                        '新增成功',
                        {
                            icon: 1,
                            time: 1000
                        },
                        function () {
                            let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            window.parent.location.reload();
                            location.href="admin.html";
                        });
                } else {
                    layer.msg('新增失败', {icon: 2});
                }
            },
            error: function (o) {
            }
        });
        return false;
    });
    form.render();//重点在这里
});